﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_newslist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["login"] == null)
            {
                Response.Redirect("login.aspx");
            }
            else
            {
                rptdatabind();
            }
        }    
    }

    private void rptdatabind()
    {
        YqhData obj = new YqhData();
        AspNetPager1.RecordCount = Convert.ToInt32(obj.ExecuteScalar("select count(*) from news"));
        int pageindex = AspNetPager1.CurrentPageIndex - 1;
        int pagesize = AspNetPager1.PageSize;
        string sql = "select nid,naddname,tname,nsubject,ndate from news inner join newstype on news.ntypeid = newstype.tid order by ndate desc";
        rptnewslist.DataSource = obj.ExecuteDataSet(sql,pageindex,pagesize);
        rptnewslist.DataBind();
    }

    protected void rptnewslist_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        YqhData obj = new YqhData();
        switch (e.CommandName.ToLower())
        {
            case "del":
                string sql = string.Format("delete news where nid={0}", e.CommandArgument);
                obj.ExecuteSql(sql);
                rptdatabind();
                break;
            case "e":
                Response.Redirect(string.Format("newsedit.aspx?op=e&id={0}", e.CommandArgument));
                break;
        }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        rptdatabind();
    }
}
